package com.fast.alden.portal.web.controller;

import com.fast.alden.common.entity.dto.ChangePasswordParam;
import com.fast.alden.data.model.PortalUser;
import com.fast.alden.portal.entity.dto.PortalUserProfile;
import com.fast.alden.portal.service.PersonalCenterPortalService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/personal-center")
public class PersonalCenterPortalController {
    @Resource
    private PersonalCenterPortalService personalCenterPortalService;

    @Operation(summary = "获取个人信息")
    @GetMapping("/retrieve")
    public PortalUserProfile retrieveMessage() {
        return personalCenterPortalService.retrieve();
    }

    @Operation(summary = "修改个人信息")
    @PutMapping("/update")
    public void update(@RequestBody PortalUser user) {
        personalCenterPortalService.update(user);
    }

    @Operation(summary = "修改密码")
    @PostMapping("/change-password")
    public void changePassword(@RequestBody @Validated ChangePasswordParam param) {
        personalCenterPortalService.changePassword(param);
    }

    @Operation(summary = "修改头像")
    @PostMapping("/update-avatar")
    public void updateAvatar(@RequestParam("file") MultipartFile file) throws IOException {
        personalCenterPortalService.updateAvatar(file);
    }

    @Operation(summary = "删除头像")
    @PostMapping("/remove-avatar")
    public void removeAvatar() {
        personalCenterPortalService.removeAvatar();
    }
}
